package vip.xiaonuo.applet;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.core.annotion.BusinessLog;
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import vip.xiaonuo.modular.appuser.param.RegisterUserInfo;
import vip.xiaonuo.modular.appuser.param.WxUserRegister;
import vip.xiaonuo.modular.appuser.service.AppUserService;
import vip.xiaonuo.sys.modular.dict.param.SysDictDataParam;
import vip.xiaonuo.sys.modular.dict.service.SysDictDataService;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@Api(tags = "小程序公共接口")
@RequestMapping("/app")
public class AppletCommonController {

    @Resource
    private AppUserService appUserService;

    @Resource
    private SysDictDataService sysDictDataService;


    /**
     * 发送短信验证码
     * @param phone
     * @return
     */
    @ApiOperation("发送短信验证码")
    @GetMapping("/user/sendSmsCode")
    public ResponseData senSmSCode(@RequestParam("phone") String phone){
        appUserService.sendSmsCode(phone);
        return new SuccessResponseData();
    }

    /**
     * 手机短信登录功能
     * @param
     */
    @ApiOperation("短信进行登录")
    @PostMapping("/user/loginOfSms")
    public ResponseData loginOfSms(@RequestBody Map map){
        return new SuccessResponseData(appUserService.login(map));
    }



    /**
     * 新用户注册
     * @param
     * @return
     */
    @PostMapping("/user/register")
    @ApiOperation("新用户注册")
    public ResponseData register(@RequestBody RegisterUserInfo userInfo){
        appUserService.registerUser(userInfo);
        return new SuccessResponseData();
    }

    @PostMapping("/user/wxLogin")
    @ApiOperation("微信登录,新用户并进行注册")
    public ResponseData wxLogin(@RequestBody WxUserRegister wxUserRegister){
        return new SuccessResponseData(appUserService.registerByWxUserInfo(wxUserRegister));
    }



    /**
     * 根据用户手机号查询对应信息
     *
     * @author wanglei
     * @date 2021-08-25 18:59:23
     */
    @ApiOperation("根据用户手机号查询对应信息")
    @GetMapping("/user/getUserByPhone")
    public ResponseData getUserByPhone(@RequestParam String phone) {
        return new SuccessResponseData(appUserService.getByPhone(phone));
    }

    /**
     * 根据用户id获取邀请码或生成邀请码
     *
     * @author wanglei
     * @date 2021-08-25 18:59:23
     */
    @ApiOperation(value = "根据用户手机获取邀请码或生成邀请码")
    @GetMapping("/user/generateInvitationCode")
    public ResponseData generateInvitationCode(@RequestParam String phone) {
        return new SuccessResponseData(appUserService.generateInvitationCode((phone)));
    }


    /**
     * 根据用户电话进行登录
     * @param phone
     * @return
     */
    @GetMapping("/user/login")
    public ResponseData login(@RequestParam("phone") String phone){
        return new SuccessResponseData(appUserService.login(phone));
    }

    /**
     * 邀请拉新
     * @param phone
     * @return
     */
    @ApiOperation(value = "获取分销")
    @GetMapping("/user/invitationList")
    public ResponseData invitationList(@RequestParam("phone") String phone){
        return new SuccessResponseData(appUserService.invitationList(phone));
    }

    /**
     *
     * @param sysDictDataParam  typeId=1478291149031002114
     * @return
     */
    @GetMapping("/sysDictData/list")
    @ApiOperation(value = "获取行业下拉  路径参数 typeId=1478291149031002114")
    @BusinessLog(title = "系统字典值_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(@Validated(SysDictDataParam.list.class) SysDictDataParam sysDictDataParam) {
        return new SuccessResponseData(sysDictDataService.list(sysDictDataParam));
    }



}
